package com.ruoyi.web.controller.cat;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cat.domain.AdTicketRoll;
import com.ruoyi.cat.service.IAdTicketRollService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 票卷相关内容Controller
 * 
 * @author ruoyi
 * @date 2025-07-16
 */
@RestController
@RequestMapping("/system/roll")
public class AdTicketRollController extends BaseController
{
    @Autowired
    private IAdTicketRollService adTicketRollService;

    /**
     * 查询票卷相关内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:roll:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdTicketRoll adTicketRoll)
    {
        startPage();
        List<AdTicketRoll> list = adTicketRollService.selectAdTicketRollList(adTicketRoll);
        return getDataTable(list);
    }

    /**
     * 导出票卷相关内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:roll:export')")
    @Log(title = "票卷相关内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdTicketRoll adTicketRoll)
    {
        List<AdTicketRoll> list = adTicketRollService.selectAdTicketRollList(adTicketRoll);
        ExcelUtil<AdTicketRoll> util = new ExcelUtil<AdTicketRoll>(AdTicketRoll.class);
        util.exportExcel(response, list, "票卷相关内容数据");
    }

    /**
     * 获取票卷相关内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:roll:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adTicketRollService.selectAdTicketRollById(id));
    }

    /**
     * 新增票卷相关内容
     */
    @PreAuthorize("@ss.hasPermi('system:roll:add')")
    @Log(title = "票卷相关内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdTicketRoll adTicketRoll)
    {
        return toAjax(adTicketRollService.insertAdTicketRoll(adTicketRoll));
    }

    @PostMapping("modifyState")
    public AjaxResult modifyState(@RequestBody AdTicketRoll adTicketRoll)
    {
        AdTicketRoll adTicketRoll1 =  adTicketRollService.selectAdTicketRollByIdBy(adTicketRoll.getId());
        if (adTicketRoll1.getState().equals("1")){
            adTicketRoll.setState("0");
        }else {
            adTicketRoll.setState("1");
        }
        return toAjax(adTicketRollService.updateAdTicketRoll(adTicketRoll));
    }

    /**
     * 修改票卷相关内容
     */
    @PreAuthorize("@ss.hasPermi('system:roll:edit')")
    @Log(title = "票卷相关内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdTicketRoll adTicketRoll)
    {
        return toAjax(adTicketRollService.updateAdTicketRoll(adTicketRoll));
    }

    /**
     * 删除票卷相关内容
     */
    @PreAuthorize("@ss.hasPermi('system:roll:remove')")
    @Log(title = "票卷相关内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adTicketRollService.deleteAdTicketRollByIds(ids));
    }
}
